* This file codes Study 3 data for Timothy J. Ryan, 
* "Actions Versus Consequences in Political Arguments: Insights 
* from Moral Psychology" (JOP). Analysis was conducted on 
* Stata/SE 14.2 for Mac (64-bit Intel).

insheet using "Study3_raw.csv", clear

* Moral conviction
alpha gcsmor1 gcsmor2, gen(gcsmor)
replace gcsmor = (gcsmor-1)/4
alpha sssmor1 sssmor2, gen(sssmor)
replace sssmor = (sssmor-1)/4
alpha iismor1 iismor2, gen(iismor)
replace iismor = (iismor-1)/4
alpha nusmor1 nusmor2, gen(nusmor)
replace nusmor = (nusmor-1)/4
alpha txsmor1 txsmor2, gen(txsmor)
replace txsmor = (txsmor-1)/4

foreach var of varlist gcimp ssimp iiimp nuimp tximp {
	replace `var' = (`var'-1)/4
	}

foreach var of varlist gcrelev ssrelev iirelev nurelev txrelev {
	replace `var' = (`var'-1)/4
	}

foreach var of varlist gcext ssext iiext nuext txext {
	recode `var' (4 = 0) (3 5 = 1) (2 6 = 2) (1 7 = 3), gen(`var'fold2)
	gen `var'fold = `var'fold2/3
	drop `var'fold2
	}	

* Attitude change
gen sschange2 = ssreveald - ssext if ssreveald!=. //reveald is the GOP-style argument presented to Democrats
replace sschange2 = ssext - ssrevealr if ssrevealr!=.

gen gcchange2 = gcreveald - gcext if gcreveald!=.
replace gcchange2 = gcext - gcrevealr if gcrevealr!=.

gen iichange2 = iiext - iireveald if iireveald!=.
replace iichange2 = iirevealr - iiext if iirevealr!=.

gen nuchange2 = nuext - nureveald if nureveald!=.
replace nuchange2 = nurevealr - nuext if nurevealr!=.

gen txchange2 = txreveald - txext if txreveald!=.
replace txchange2 = txext - txrevealr if txrevealr!=.

foreach var in ss gc tx nu ii {
	gen `var'change = `var'change2 / 6
	drop `var'change2
	}	

* Partisanship
gen pidr2 = .
replace pidr2 = 0 if demstrong==1
replace pidr2 = 1 if demstrong==2
replace pidr2 = 2 if partclose==2
replace pidr2 = 3 if partclose==3
replace pidr2 = 4 if partclose==1
replace pidr2 = 5 if repstrong==2
replace pidr2 = 6 if repstrong==1	
	
save "Study3_working_wide.dta", replace

foreach iss in gc ss nu ii tx {
	foreach dv in imp extfold relev smor change {
		rename `iss'`dv' `dv'`iss'
		}
	}

reshape long imp extfold relev smor change, i(caseid) j(gc) string
encode gc, gen(issue) // Note: should generate a variable coding each issue as 1, 2, 3, 4, or 5. One machine of mine codes it as 2, 3, 4, 5, 7 for some reason, so this is worth checking.
drop gc

save "Study3_working_long.dta", replace
